#include <stdio.h>
#include <stdlib.h>
#include <string.h>

long data[1000];


int test(int elems, int stride) {
    long i, sx2=stride*2, sx3=stride*3, sx4=stride*4;
    long acc0 = 0, acc1 = 0, acc2 = 0, acc3 = 0;
    long length = elems, limit = length - sx4;
    for (i = 0; i < limit; i += sx4) {
        acc0 = acc0 + data[i];
        acc1 = acc1 + data[i+stride];
        acc2 = acc2 + data[i+sx2];
        acc3 = acc3 + data[i+sx3];
        printf("access %d\n", i);
        printf("access %d\n", i + stride);
        printf("access %d\n", i + sx2);
        printf("access %d\n", i + sx3);
    }

    for (; i < length; i++) {
        acc0 = acc0 + data[i];
        printf("access %d\n", i);
    }
    return ((acc0 + acc1) + (acc2 + acc3));
}

int main(int argc, char const *argv[])
{
    for(int i = 0; i < 1000; i++) {
        data[i] = i;
    }
    int elems;
    sscanf(argv[1], "%d", &elems); 
    int stride;
    sscanf(argv[2], "%d", &stride); 

    printf("long int size:%d\n",sizeof(long));
    printf("double size:%d\n",sizeof(double));
    printf("elems:%d, stride:%d\n", elems, stride);

    test(elems,stride);

    return 0;
}

